package model.dlct.entities;

import oracle.jbo.Key;
import oracle.jbo.RowSet;
import oracle.jbo.ViewCriteria;
import oracle.jbo.ViewCriteriaRow;
import oracle.jbo.ViewObject;
import oracle.jbo.domain.BlobDomain;
import oracle.jbo.domain.ClobDomain;
import oracle.jbo.domain.DBSequence;
import oracle.jbo.domain.Date;
import oracle.jbo.domain.Number;
import oracle.jbo.server.AttributeDefImpl;
import oracle.jbo.server.EntityDefImpl;
import oracle.jbo.server.EntityImpl;
// ---------------------------------------------------------------------
// ---    File generated by Oracle ADF Business Components Design Time.
// ---    Tue Mar 12 14:20:28 ICT 2013
// ---    Custom code may be added to this class.
// ---    Warning: Do not modify method signatures of generated methods.
// ---------------------------------------------------------------------
public class DlctGtSgdTtImpl extends EntityImpl {
    private static EntityDefImpl mDefinitionObject;

    /**
     * AttributesEnum: generated enum for identifying attributes and accessors. Do not modify.
     */
    public enum AttributesEnum {
        Id {
            public Object get(DlctGtSgdTtImpl obj) {
                return obj.getId();
            }

            public void put(DlctGtSgdTtImpl obj, Object value) {
                obj.setId((DBSequence)value);
            }
        }
        ,
        DlctSanGiaoDichId {
            public Object get(DlctGtSgdTtImpl obj) {
                return obj.getDlctSanGiaoDichId();
            }

            public void put(DlctGtSgdTtImpl obj, Object value) {
                obj.setDlctSanGiaoDichId((Number)value);
            }
        }
        ,
        DlctTruongTtId {
            public Object get(DlctGtSgdTtImpl obj) {
                return obj.getDlctTruongTtId();
            }

            public void put(DlctGtSgdTtImpl obj, Object value) {
                obj.setDlctTruongTtId((Number)value);
            }
        }
        ,
        ValVarchar {
            public Object get(DlctGtSgdTtImpl obj) {
                return obj.getValVarchar();
            }

            public void put(DlctGtSgdTtImpl obj, Object value) {
                obj.setValVarchar((String)value);
            }
        }
        ,
        ValNumber {
            public Object get(DlctGtSgdTtImpl obj) {
                return obj.getValNumber();
            }

            public void put(DlctGtSgdTtImpl obj, Object value) {
                obj.setValNumber((Number)value);
            }
        }
        ,
        ValDate {
            public Object get(DlctGtSgdTtImpl obj) {
                return obj.getValDate();
            }

            public void put(DlctGtSgdTtImpl obj, Object value) {
                obj.setValDate((Date)value);
            }
        }
        ,
        ValClob {
            public Object get(DlctGtSgdTtImpl obj) {
                return obj.getValClob();
            }

            public void put(DlctGtSgdTtImpl obj, Object value) {
                obj.setValClob((ClobDomain)value);
            }
        }
        ,
        ValBlob {
            public Object get(DlctGtSgdTtImpl obj) {
                return obj.getValBlob();
            }

            public void put(DlctGtSgdTtImpl obj, Object value) {
                obj.setValBlob((BlobDomain)value);
            }
        }
        ,
        HtFileId {
            public Object get(DlctGtSgdTtImpl obj) {
                return obj.getHtFileId();
            }

            public void put(DlctGtSgdTtImpl obj, Object value) {
                obj.setHtFileId((Number)value);
            }
        }
        ,
        DuyNhat {
            public Object get(DlctGtSgdTtImpl obj) {
                return obj.getDuyNhat();
            }

            public void put(DlctGtSgdTtImpl obj, Object value) {
                obj.setDuyNhat((Number)value);
            }
        }
        ,
        DlctSanGiaoDich {
            public Object get(DlctGtSgdTtImpl obj) {
                return obj.getDlctSanGiaoDich();
            }

            public void put(DlctGtSgdTtImpl obj, Object value) {
                obj.setDlctSanGiaoDich((DlctSanGiaoDichImpl)value);
            }
        }
        ,
        DlctTruongTt {
            public Object get(DlctGtSgdTtImpl obj) {
                return obj.getDlctTruongTt();
            }

            public void put(DlctGtSgdTtImpl obj, Object value) {
                obj.setDlctTruongTt((EntityImpl)value);
            }
        }
        ,
        DlctGtSgdTtView1 {
            public Object get(DlctGtSgdTtImpl obj) {
                return obj.getDlctGtSgdTtView1();
            }

            public void put(DlctGtSgdTtImpl obj, Object value) {
                obj.setAttributeInternal(index(), value);
            }
        }
        ;
        private static AttributesEnum[] vals = null;
        private static int firstIndex = 0;

        public abstract Object get(DlctGtSgdTtImpl object);

        public abstract void put(DlctGtSgdTtImpl object, Object value);

        public int index() {
            return AttributesEnum.firstIndex() + ordinal();
        }

        public static int firstIndex() {
            return firstIndex;
        }

        public static int count() {
            return AttributesEnum.firstIndex() + AttributesEnum.staticValues().length;
        }

        public static AttributesEnum[] staticValues() {
            if (vals == null) {
                vals = AttributesEnum.values();
            }
            return vals;
        }
    }


    public static final int ID = AttributesEnum.Id.index();
    public static final int DLCTSANGIAODICHID = AttributesEnum.DlctSanGiaoDichId.index();
    public static final int DLCTTRUONGTTID = AttributesEnum.DlctTruongTtId.index();
    public static final int VALVARCHAR = AttributesEnum.ValVarchar.index();
    public static final int VALNUMBER = AttributesEnum.ValNumber.index();
    public static final int VALDATE = AttributesEnum.ValDate.index();
    public static final int VALCLOB = AttributesEnum.ValClob.index();
    public static final int VALBLOB = AttributesEnum.ValBlob.index();
    public static final int HTFILEID = AttributesEnum.HtFileId.index();
    public static final int DUYNHAT = AttributesEnum.DuyNhat.index();
    public static final int DLCTSANGIAODICH = AttributesEnum.DlctSanGiaoDich.index();
    public static final int DLCTTRUONGTT = AttributesEnum.DlctTruongTt.index();
    public static final int DLCTGTSGDTTVIEW1 = AttributesEnum.DlctGtSgdTtView1.index();

    /**
     * This is the default constructor (do not remove).
     */
    public DlctGtSgdTtImpl() {
    }


    /**
     * @return the definition object for this instance class.
     */
    public static synchronized EntityDefImpl getDefinitionObject() {
        if (mDefinitionObject == null) {
            mDefinitionObject = EntityDefImpl.findDefObject("model.dlct.entities.DlctGtSgdTt");
        }
        return mDefinitionObject;
    }

    /**
     * Gets the attribute value for Id, using the alias name Id.
     * @return the Id
     */
    public DBSequence getId() {
        return (DBSequence)getAttributeInternal(ID);
    }

    /**
     * Sets <code>value</code> as the attribute value for Id.
     * @param value value to set the Id
     */
    public void setId(DBSequence value) {
        setAttributeInternal(ID, value);
    }

    /**
     * Gets the attribute value for DlctSanGiaoDichId, using the alias name DlctSanGiaoDichId.
     * @return the DlctSanGiaoDichId
     */
    public Number getDlctSanGiaoDichId() {
        return (Number)getAttributeInternal(DLCTSANGIAODICHID);
    }

    /**
     * Sets <code>value</code> as the attribute value for DlctSanGiaoDichId.
     * @param value value to set the DlctSanGiaoDichId
     */
    public void setDlctSanGiaoDichId(Number value) {
        setAttributeInternal(DLCTSANGIAODICHID, value);
    }

    /**
     * Gets the attribute value for DlctTruongTtId, using the alias name DlctTruongTtId.
     * @return the DlctTruongTtId
     */
    public Number getDlctTruongTtId() {
        return (Number)getAttributeInternal(DLCTTRUONGTTID);
    }

    /**
     * Sets <code>value</code> as the attribute value for DlctTruongTtId.
     * @param value value to set the DlctTruongTtId
     */
    public void setDlctTruongTtId(Number value) {
        setAttributeInternal(DLCTTRUONGTTID, value);
    }

    /**
     * Gets the attribute value for ValVarchar, using the alias name ValVarchar.
     * @return the ValVarchar
     */
    public String getValVarchar() {
        return (String)getAttributeInternal(VALVARCHAR);
    }

    /**
     * Sets <code>value</code> as the attribute value for ValVarchar.
     * @param value value to set the ValVarchar
     */
    public void setValVarchar(String value) {
        setAttributeInternal(VALVARCHAR, value);
    }

    /**
     * Gets the attribute value for ValNumber, using the alias name ValNumber.
     * @return the ValNumber
     */
    public Number getValNumber() {
        return (Number)getAttributeInternal(VALNUMBER);
    }

    /**
     * Sets <code>value</code> as the attribute value for ValNumber.
     * @param value value to set the ValNumber
     */
    public void setValNumber(Number value) {
        setAttributeInternal(VALNUMBER, value);
    }

    /**
     * Gets the attribute value for ValDate, using the alias name ValDate.
     * @return the ValDate
     */
    public Date getValDate() {
        return (Date)getAttributeInternal(VALDATE);
    }

    /**
     * Sets <code>value</code> as the attribute value for ValDate.
     * @param value value to set the ValDate
     */
    public void setValDate(Date value) {
        setAttributeInternal(VALDATE, value);
    }

    /**
     * Gets the attribute value for ValClob, using the alias name ValClob.
     * @return the ValClob
     */
    public ClobDomain getValClob() {
        return (ClobDomain)getAttributeInternal(VALCLOB);
    }

    /**
     * Sets <code>value</code> as the attribute value for ValClob.
     * @param value value to set the ValClob
     */
    public void setValClob(ClobDomain value) {
        setAttributeInternal(VALCLOB, value);
    }

    /**
     * Gets the attribute value for ValBlob, using the alias name ValBlob.
     * @return the ValBlob
     */
    public BlobDomain getValBlob() {
        return (BlobDomain)getAttributeInternal(VALBLOB);
    }

    /**
     * Sets <code>value</code> as the attribute value for ValBlob.
     * @param value value to set the ValBlob
     */
    public void setValBlob(BlobDomain value) {
        setAttributeInternal(VALBLOB, value);
    }

    /**
     * Gets the attribute value for HtFileId, using the alias name HtFileId.
     * @return the HtFileId
     */
    public Number getHtFileId() {
        return (Number)getAttributeInternal(HTFILEID);
    }

    /**
     * Sets <code>value</code> as the attribute value for HtFileId.
     * @param value value to set the HtFileId
     */
    public void setHtFileId(Number value) {
        setAttributeInternal(HTFILEID, value);
    }

    /**
     * Gets the attribute value for DuyNhat, using the alias name DuyNhat.
     * @return the DuyNhat
     */
    public Number getDuyNhat() {
        return (Number)getAttributeInternal(DUYNHAT);
    }

    /**
     * Sets <code>value</code> as the attribute value for DuyNhat.
     * @param value value to set the DuyNhat
     */
    public void setDuyNhat(Number value) {
        setAttributeInternal(DUYNHAT, value);
    }

    /**
     * getAttrInvokeAccessor: generated method. Do not modify.
     * @param index the index identifying the attribute
     * @param attrDef the attribute

     * @return the attribute value
     * @throws Exception
     */
    protected Object getAttrInvokeAccessor(int index,
                                           AttributeDefImpl attrDef) throws Exception {
        if ((index >= AttributesEnum.firstIndex()) && (index < AttributesEnum.count())) {
            return AttributesEnum.staticValues()[index - AttributesEnum.firstIndex()].get(this);
        }
        return super.getAttrInvokeAccessor(index, attrDef);
    }

    /**
     * setAttrInvokeAccessor: generated method. Do not modify.
     * @param index the index identifying the attribute
     * @param value the value to assign to the attribute
     * @param attrDef the attribute

     * @throws Exception
     */
    protected void setAttrInvokeAccessor(int index, Object value,
                                         AttributeDefImpl attrDef) throws Exception {
        if ((index >= AttributesEnum.firstIndex()) && (index < AttributesEnum.count())) {
            AttributesEnum.staticValues()[index - AttributesEnum.firstIndex()].put(this, value);
            return;
        }
        super.setAttrInvokeAccessor(index, value, attrDef);
    }

    /**
     * @return the associated entity DlctSanGiaoDichImpl.
     */
    public DlctSanGiaoDichImpl getDlctSanGiaoDich() {
        return (DlctSanGiaoDichImpl)getAttributeInternal(DLCTSANGIAODICH);
    }

    /**
     * Sets <code>value</code> as the associated entity DlctSanGiaoDichImpl.
     */
    public void setDlctSanGiaoDich(DlctSanGiaoDichImpl value) {
        setAttributeInternal(DLCTSANGIAODICH, value);
    }

    /**
     * @return the associated entity oracle.jbo.server.EntityImpl.
     */
    public EntityImpl getDlctTruongTt() {
        return (EntityImpl)getAttributeInternal(DLCTTRUONGTT);
    }

    /**
     * Sets <code>value</code> as the associated entity oracle.jbo.server.EntityImpl.
     */
    public void setDlctTruongTt(EntityImpl value) {
        setAttributeInternal(DLCTTRUONGTT, value);
    }

    /**
     * Gets the view accessor <code>RowSet</code> DlctGtSgdTtView1.
     */
    public RowSet getDlctGtSgdTtView1() {
        return (RowSet)getAttributeInternal(DLCTGTSGDTTVIEW1);
    }

    /**
     * @param id key constituent

     * @return a Key object based on given key constituents.
     */
    public static Key createPrimaryKey(DBSequence id) {
        return new Key(new Object[]{id});
    }

    /**
     * Validation method for DlctGtSgdTt.
     */
    public boolean validateDuyNhat() {
        if (getDlctSanGiaoDichId() != null &&
            getDlctSanGiaoDichId().toString().isEmpty() == false &&
            getDlctTruongTtId() != null &&
            getDlctTruongTtId().toString().isEmpty() == false) {
            if (getDuyNhat() != null && getDuyNhat().toString().equals("2")) {
                ViewObject vo = getDlctGtSgdTtView1().getViewObject();
                ViewCriteria vc = vo.createViewCriteria();

                ViewCriteriaRow vcr = vc.createViewCriteriaRow();
                vcr.setConjunction(ViewCriteriaRow.VC_CONJ_NOT);
                vcr.setAttribute(DLCTSANGIAODICHID, getDlctSanGiaoDichId());
                vc.add(vcr);
                vcr = vc.createViewCriteriaRow();
                vcr.setConjunction(ViewCriteriaRow.VC_CONJ_AND);
                vcr.setUpperColumns(true);
                boolean check = false;
                vcr.setAttribute(DLCTTRUONGTTID, getDlctTruongTtId());
                if (getValDate() != null) {
                    vcr.setAttribute(VALDATE, getValDate());
                    check = true;
                }
                if (getValNumber() != null) {
                    vcr.setAttribute(VALNUMBER, getValNumber());
                    check = true;
                }
                if (getValVarchar() != null) {
                    vcr.setAttribute(VALVARCHAR,
                                     getValVarchar().toUpperCase());
                    check = true;
                }
                if (check) {
                    vc.add(vcr);
                    vo.getViewCriteriaManager().clearViewCriterias();
                    vo.getViewCriteriaManager().applyViewCriteria(vc);
                    vo.executeQuery();
                    return vo.getEstimatedRowCount() == 0;
                }
            }
        }
        return true;
    }


}
